package com.acwing.lc.part1;

/**
 * @author rkc
 * @date 2022/9/15 8:58
 */
public class LC44通配符匹配 {

    public boolean isMatch(String s, String p) {
        int n = s.length(), m = p.length();
        s = ' ' + s;
        p = ' ' + p;
        boolean[][] f = new boolean[n + 10][m + 10];
        f[0][0] = true;
        for (int i = 0; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (p.charAt(j) == '*') {
                    f[i][j] = f[i][j - 1] || (i > 0 && f[i - 1][j]);
                } else {
                    f[i][j] = (s.charAt(i) == p.charAt(j) || p.charAt(j) == '?') && (i > 0 && f[i - 1][j - 1]);
                }
            }
        }
        return f[n][m];
    }
}
